//
//  RegistGiftBox.m
//  PigMarket
//
//  Created by 张敬 on 2019/9/4.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "RegistGiftBox.h"

//展示Viwe高度
#define BoxW  KScreenWidth - 60
#define BoxH 413


@interface RegistGiftBox()

@property (nonatomic, strong) UIView *mContentView;
@property (nonatomic, strong) UILabel *titlelab; //金钱
@property (nonatomic, strong) UILabel *priceLab; //金钱

@property (nonatomic, strong) UILabel *detailLab; //标题
@property (nonatomic, strong) UILabel *planLab1; //金钱



@property (nonatomic, strong) UIButton *closeBtn; //关闭按钮
@property (nonatomic, strong) UIButton *okBtn;


@end


@implementation RegistGiftBox


- (instancetype)init{
    self = [super initWithFrame:CGRectMake(0, 0, KScreenWidth, KScreenHeight)];
    if (self) {
        [self setupContent];
        
    }
    return self;
}

- (void)setupContent{
    
    self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    {
        _mContentView.size = CGSizeMake(BoxW, BoxH);
        _mContentView.center = self.center;
        _mContentView.mj_y -= 70;
        _mContentView.mj_x = 35;
    }
    
    {
        _titlelab.size = CGSizeMake(BoxW, 66);
        [_titlelab sizeToFit];
        _titlelab.mj_x = (BoxW - _titlelab.width)/2.0;
        _titlelab.mj_y = 16;
        
    }

    {
        _priceLab.size = CGSizeMake(BoxW - 70, 34);
        _priceLab.mj_x =  (BoxW - _priceLab.width)/2.0;;
        _priceLab.mj_y = _titlelab.bottom + 5;
    }

    
    
    {
        _detailLab.size = CGSizeMake(BoxW - 47, 54);
        _detailLab.mj_x = 29;
        _detailLab.mj_y = 229;
        
    }
    
    
    {
        _planLab1.size = CGSizeMake(BoxW - 47, 100);
        [_planLab1 sizeToFit];
        _planLab1.mj_x = 29;
        _planLab1.mj_y = _detailLab.bottom + 8;
        
    }

    
    {
        _okBtn.size = CGSizeMake(131, 30);
        _okBtn.mj_x = (BoxW - _okBtn.width)/2.0;
        _okBtn.mj_y = 131;
    }
    
    
    {
        //关闭按钮
        _closeBtn.size = CGSizeMake(50, 50);
        _closeBtn.mj_x = (_mContentView.width - _closeBtn.width)/2.0;
        _closeBtn.mj_y = _mContentView.height + 21;
        
    }
    
}


- (void)showView{
    
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    [window addSubview:self];
    
    [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissView)]];
    [self addSubview:self.mContentView];
    
    CGAffineTransform firstTransform = CGAffineTransformScale(self.transform, 0.1, 0.1);
    [_mContentView setTransform:firstTransform];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.25];
    _mContentView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1, 1);
    [UIView commitAnimations];
    
}


- (void)dismissView{
    self.alpha = 0;
    self.mContentView.alpha = 0;
    [self removeAllSubviews];
    [self.mContentView removeAllSubviews];
}


#pragma mark - setter and getter
- (UIView *)mContentView{
    if (!_mContentView) {
        _mContentView = [UIView new];
        
        UIImage *image = [UIImage imageNamed:@"adopt_box_bg"];
        _mContentView.layer.contents = (__bridge id)image.CGImage;
        

        
        [_mContentView addSubview:self.closeBtn];
        
        [_mContentView addSubview:self.titlelab];
        [_mContentView addSubview:self.planLab1];
        [_mContentView addSubview:self.detailLab];
        [_mContentView addSubview:self.priceLab];
        
        [_mContentView addSubview:self.okBtn];
        
        
    }
    
    return _mContentView;
}



- (UILabel *)detailLab{
    if (!_detailLab) {
        _detailLab = [UILabel new];
        _detailLab.text = @"想进一步成为共享会员权限，请先领养一只可爱的小猪猪，您将获得以下权益：";
        _detailLab.textColor = UIColorFromRGB(0xFF8A00);
        _detailLab.font = mMediumFont(14);
        _detailLab.numberOfLines = 0;
        _detailLab.textAlignment = 0;
        NSAttributedString *aims = [_detailLab.text getParagraphAttributedStringWithLineSpacing:10];
        _detailLab.attributedText = aims;
    }
    
    return _detailLab;
}


- (UILabel *)planLab1{
    if (!_planLab1) {
        _planLab1 = [UILabel new];
        _planLab1.textColor = UIColorFromRGB(0xECC143);
        _planLab1.text = @"1. 权益内容权益内容权益内容权益内容权 \n2. 权益内容权益内容权益内容权益内容权益内 \n3. 权益内容权益内容权益内容权益 \n4. 权益内容权益内容权益内";
        NSMutableAttributedString *aims = [_planLab1.text getParagraphAttributedStringWithLineSpacing: 8];
        _planLab1.attributedText = aims;
        _planLab1.textAlignment = 0;
        _planLab1.numberOfLines = 0;
        _planLab1.font = mFont(13);
    }
    return _planLab1;
}

- (UILabel *)titlelab{
    if (!_titlelab) {
        _titlelab = [UILabel new];
        _titlelab.textColor = UIColorFromRGB(0xFF8A00);
        _titlelab.text = @"恭喜您注册会员成功\n获得豚券";
        NSMutableAttributedString *aims = [_titlelab.text getParagraphAttributedStringWithLineSpacing: 8];
        _titlelab.attributedText = aims;
        _titlelab.textAlignment = 1;
        _titlelab.numberOfLines = 0;
        _titlelab.font = mFont(15);
    }
    return _titlelab;
}

- (UILabel *)priceLab{
    if (!_priceLab) {
        _priceLab = [UILabel new];
        _priceLab.text = @"60¥";
        _priceLab.textAlignment = 1;
        
        NSMutableAttributedString *aims = [[NSMutableAttributedString alloc] initWithString:_priceLab.text];
        [aims addAttribute:NSFontAttributeName value:mSemiboldFont(20) range:NSMakeRange(0, _priceLab.text.length)];
        [aims addAttribute:NSFontAttributeName value:mSemiboldFont(38) range:NSMakeRange(0, _priceLab.text.length-1)];
        [aims addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0xFF8A00) range:NSMakeRange(0, _priceLab.text.length)];
        _priceLab.attributedText = aims;
        
    }
    return _priceLab;
}


- (UIButton *)okBtn{
    
    if (!_okBtn) {
        _okBtn = [UIButton makeButtonWithText:@"查看我的豚券" textColor:UIColorFromRGB(0xFFE8B1) font:mMediumFont(15) textAliment:1 cornerRadius:5];
        [_okBtn setBackgroundImage:[UIImage imageNamed:@"btn_orange_bg"] forState:UIControlStateNormal];
        _okBtn.backgroundColor = KClearColor;
        
        @weakify(self);
        _okBtn.tapBlock = ^{
            @strongify(self);
            [self dismissView];
            
            if (self.dealOkBlock) {
                self.dealOkBlock();
            }
        };
    }
    return _okBtn;
}


- (UIButton *)closeBtn{
    if (!_closeBtn) {
        
        _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeBtn setImage:[UIImage imageNamed:@"meat_separater_close"] forState:UIControlStateNormal];
        [_closeBtn addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _closeBtn;
}



@end
